﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ServerConsole
{
    class Program
    {
       static SC.Net.TcpServer ts = new SC.Net.TcpServer();
        static void Main(string[] args)
        {
            ts.StartListen("127.0.0.1", 9999);
            ts.ReciveData += new SC.Net.TcpServer.TcpServerRevDataEvent(ts_ReciveData);
            ts.DisConnect += new SC.Net.TcpServer.TcpServerDisConnectEvent(ts_DisConnect);
            ts.Error += new SC.Net.TcpServer.TcpServerErrorEvent(ts_Error);
            while (true)
            {
                Console.ReadLine();
            }
        }

        static void ts_Error(object sender, SC.Net.TcpServerErrorEventArgs e)
        {
            Console.WriteLine(e.Exception.Message);
        }

        static void ts_DisConnect(object sender, SC.Net.TcpSeverDisConnectEventArgs e)
        {
            Console.WriteLine(e.Exception);
        }

        static void ts_ReciveData(object sender, SC.Net.TcpServerRevDataEventArgs e)
        {
            System.IO.MemoryStream stream=new System.IO.MemoryStream(e.Data);
            System.IO.StreamReader sr=new System.IO.StreamReader(stream);
            string str=sr.ReadToEnd();
            sr.Close();
            stream.Close();
            ts.Send(e.Data, e.Data.Length, e.Handler);
            Console.WriteLine(str.Trim());
            Console.ReadLine();
        }
    }
}
